package com.xbongbong.saas.enums.business;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.BusinessFieldEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Getter
public enum WaitInstockEnum {

    PRODUCT_IMGS("file_1","enum.product.attrName.product_imgs", FieldTypeEnum.IMAGE.getType(),"productImgs", XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),1),
    PRODUCT_NAME("productName","enum.selectProduct.attrName.product_name",FieldTypeEnum.TEXT.getType(),"product_name",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),2),
    PRODUCT_NO("productNo","enum.selectProduct.attrName.product_no",FieldTypeEnum.TEXT.getType(),"product_no",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),3),
    SPECIFICATION("specification","enum.selectProduct.attrName.specification",FieldTypeEnum.TEXT.getType(),"specification",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),4),
    UNIT("text_8","enum.waitInstock.attrName.unit",FieldTypeEnum.COMBO.getType(),"product_unit",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),4),
    STOCK("num_12","enum.waitInstock.attrName.stock",FieldTypeEnum.NUM.getType(),"stock",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),5),
    MEMO("memo","enum.selectProduct.attrName.memo",FieldTypeEnum.TEXTAREA.getType(),"memo",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),6),
    SHEET_NO("serialNo", "enum.purchase.attrName.sheet_no",  FieldTypeEnum.SERIALNO.getType(),"sheetNo",XbbRefTypeEnum.PURCHASE.getCode(),7),
    PURCHASE_NAME("text_2", "enum.purchase.attrName.purchase_name",  FieldTypeEnum.TEXT.getType()," purchaseName", XbbRefTypeEnum.PURCHASE.getCode(),8),
    SUPPLIER_ID("text_3", "enum.waitInstock.attrName.supplier_id", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),"supplierId",  XbbRefTypeEnum.PURCHASE.getCode(),9),
    SIGN_TIME("date_1", "enum.purchase.attrName.sign_time", FieldTypeEnum.DATETIME.getType(),"signTime",  XbbRefTypeEnum.PURCHASE.getCode(),10),
    ESTIMATE_ARRIVE_TIME("date_2", "enum.purchase.attrName.estimate_arrive_time",  FieldTypeEnum.DATETIME.getType(),"estimateArriveTime",XbbRefTypeEnum.PURCHASE.getCode(),11),
    STATUS("text_5", "enum.purchase.attrName.status", FieldTypeEnum.COMBO.getType(),"status",  XbbRefTypeEnum.PURCHASE.getCode(),12),
    SIGNER_ID("text_6", "enum.purchase.attrName.signer_id",  FieldTypeEnum.USER.getType(),"signerId",XbbRefTypeEnum.PURCHASE.getCode(),13),
    ADDTIME("addTime","enum.fieldType.description.addtime",FieldTypeEnum.ADDTIME.getType(),"addtime",XbbRefTypeEnum.PURCHASE.getCode(),14),
    UPDATETIME("updateTime","enum.fieldType.description.updatetime",FieldTypeEnum.UPDATETIME.getType(),"updateTime",XbbRefTypeEnum.PURCHASE.getCode(),15),
    WAIT_INSTOCK_PRODUCT("option_8","enum.waitInstock.attrName.wait_instock_product",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),"wait_instock_product",XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),15),
    ;

    private String attr;

    private String attrName;

    private Integer fieldType;

    private String saasAttr;

    private Integer linkedType;

    private Integer sort;

    WaitInstockEnum(String attr, String attrName, Integer fieldType, String saasAttr, int linkedType, int sort) {
        this.attr = attr;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.saasAttr = saasAttr;
        this.linkedType = linkedType;
        this.sort = sort;
    }

    public static Integer getSortByWaitInstockSort(String attr){
        for (WaitInstockEnum waitInstockEnum : WaitInstockEnum.values()){
            if (Objects.equals(attr,waitInstockEnum.getAttr())){
                return waitInstockEnum.getSort();
            }
        }
        return 0 ;
    }

    public static List<String> getByBusinessType(Integer businessType) {
        List<String> attrList = new ArrayList<>();
        for (WaitInstockEnum waitInstockEnum : values()) {
            if (Objects.equals(waitInstockEnum.getLinkedType(), businessType)) {
                attrList.add(waitInstockEnum.getAttr());
            }
        }
        return attrList;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static Boolean isPurchaseAndProduct (String attr){
        Boolean isProduct = true;
        for (WaitInstockEnum waitInstockEnum : WaitInstockEnum.values()){
            if (Objects.equals(attr,waitInstockEnum.getAttr())){
                Integer linkedType = waitInstockEnum.getLinkedType();
                if (Objects.equals(linkedType,XbbRefTypeEnum.PURCHASE.getCode())){
                    isProduct =  false;
                }
            }
        }
        return isProduct;
    }

    public static String getFeildName(String attr){
        for (WaitInstockEnum waitInstockEnum : WaitInstockEnum.values()){
            if (Objects.equals(attr,waitInstockEnum.getAttr())){
                return waitInstockEnum.getSaasAttr();
            }
        }
        return "update_time";
    }
}
